$(function () {

    var appPath = $("#appPath").val()
    //获取房型的号码
    let houseTypeId = $("#left_img_input").val()

    $.ajax({
        "url" : appPath+"/formVerify",
        "type" : "post",
        "data" : "type=roomRates&houseTypeId="+houseTypeId,
        "dataType" : "json",
        "success" : function (result){
            var html = "";
            for (let i = 0; i < result.length; i++) {
                var roomNumber = result[i].roomNumber
                html += "<option value='"+roomNumber+"'>"+roomNumber+"</option>"
            }
            $("#addresident_div_select2").html(html)
        },
        "error" : function (){
            alert("错")
        }
    })


    let prices = $("#add_price").val()
    //退房时间失焦计算开房几天，开放天数*房间价格
    $("#add_checkOutDate").blur(function () {
        //开房时间
        let inDat = $("#add_checkInDate").val()
        //退房时间
        let outDate = $("#add_checkOutDate").val()
        //计算毫秒
        let second = parseInt(new Date(outDate).getTime() / 1000) - parseInt(new Date(inDat).getTime() / 1000)
        //计算开房天数
        let day = parseInt(second / 60 / 60 / 24);
        //计算小时
        let hour = parseInt(second / 60 / 60)
        //是否满足一天
        if (hour % 24 == 0){
            day = day;
        }else if (hour % 24 != 0){
            day = day +1
        }
        //计算价格*开房天数
        let price = prices * day;
        $("#add_price").val(price)
    })
})